//
//  ViewController.m
//  singForYou
//
//  Created by nicolas on 2016/12/6.
//  Copyright © 2016年 nicolas. All rights reserved.
//

#import "ViewController.h"
#import "YDWaveLoadingView.h"
#import "MKMainViewController.h"

@interface ViewController ()

@property (strong, nonatomic) UIImageView *loginLeftImage;

@property (strong, nonatomic) UIImageView *loginRightImage;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self prepareUI];
    [self openDoor];
    
}

#pragma mark - Private method

- (void)prepareUI {
    
    UIImageView *backGroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    backGroundImage.image = [UIImage imageNamed:@"mk_doubleFigure"];
    [self.view addSubview:backGroundImage];
    
    UIImageView *loginLeftImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width*0.5, self.view.frame.size.height)];
    loginLeftImage.image = [UIImage imageNamed:@"mk_girl_login"];
    [self.view addSubview:loginLeftImage];
    self.loginLeftImage = loginLeftImage;

    UIImageView *loginRightImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width*0.5, 0, self.view.frame.size.width*0.5, self.view.frame.size.height)];
    loginRightImage.image = [UIImage imageNamed:@"mk_boy_login"];
    [self.view addSubview:loginRightImage];
    self.loginRightImage = loginRightImage;
    
}

- (void)openDoor {
    
    [UIView animateWithDuration:2 delay:1 options:UIViewAnimationOptionCurveEaseIn animations:^{
        self.loginLeftImage.frame = CGRectMake(-self.view.frame.size.width*0.5, 0, self.view.frame.size.width*0.5, self.view.frame.size.height);
        self.loginRightImage.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width*0.5, self.view.frame.size.height);
        
    } completion:^(BOOL finished) {
        [self addWaveLoadingView];
        [self goLoginVc];
    }];
}

- (void)addWaveLoadingView {
    
    YDWaveLoadingView *waveLoadingView = [YDWaveLoadingView loadingView];
    waveLoadingView.frame = CGRectMake(self.view.center.x-40, self.view.center.y - 260, 80, 60);
    [self.view addSubview:waveLoadingView];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [waveLoadingView startLoading];
    });
}

- (void)goLoginVc {
    
    UILabel *ideaLbl = [[UILabel alloc] initWithFrame:CGRectMake(self.view.center.x-80, self.view.center.y-170, 200, 40)];
    ideaLbl.text = @"听简单的歌,想简单的事";
    [self.view addSubview:ideaLbl];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        MKMainViewController *mainVc = [[MKMainViewController alloc] init];

        [self presentViewController:mainVc animated:YES completion:nil];
    });

}


@end
